﻿using System;
using System.Web.UI;
using Highchart.Core;
using Highchart.Core.Options;
using Highchart.Core.PlotOptions;
using Highchart.Core.ScriptServices;

namespace Highchart.UI
{    
    public class ColumnChart : Chart, IChart
    {

        protected override void OnPreRender(EventArgs e)
        {
            RenderType = RenderType.column;
            Render();
        }

        public PlotOptionsColumn PlotOptions
        {
            get
            {
                object o = ViewState["PlotOptionsColumn"];
                if (o == null)
                    return new PlotOptionsColumn();
                return (PlotOptionsColumn)o;
            }
            set { ViewState["PlotOptionsColumn"] = value; }
        }

        public void Render()
        {

            var chartOptions = new ChartOptions
            {
                ClientId = ClientID,
                Lang = Lang,
                Appearance = Appearance,
                Colors = Colors,
                RenderType = RenderType,
                Legend = Legend,
                Exporting = Exporting,
                ShowCredits = ShowCredits,
                Title = Title,
                SubTitle = SubTitle,
                Tooltip = new ToolTip(ToolTip),
                YAxis = YAxis,
                XAxis = XAxis,
                Series = Series,
                Theme = Theme,
                AjaxDataSource = AjaxDataSource,
                PlotOptions = PlotOptions
            };

            var columnChartScript = ScriptBuilder.BuildColumnChart(chartOptions);

            ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "chart_" + ClientID, columnChartScript, true);
                     
        }

    }
}
